package cn.gok.controller;

import cn.gok.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author shikundai
 * @date 2021/3/21
 * @time 14:14
 * @description
 */
@Controller
@RequestMapping("/user")
public class UserController {
    /**
     * @author shikundai
     * @date 2021/3/21
     * @time 14:14
     * @description 去往用户登录界面
     */
    @GetMapping("/login")
    public String toLogin(){
        return "login";
    }
    /**
     * @author shikundai
     * @date 2021/3/21
     * @time 14:35
     * @description 执行登录操作
     */
    @PostMapping("/login")
    public String Login(User user){
        Subject subject= SecurityUtils.getSubject();
        UsernamePasswordToken usernamePasswordToken=new UsernamePasswordToken(user.getName(), user.getPsw());
        subject.login(usernamePasswordToken);
        return "redirect:/user/center";
    }




    /**
     * @author shikundai
     * @date 2021/3/21
     * @time 14:15
     * @description 去往用户中心
     */
    @GetMapping("/center")
    public String toCenter(){
        return "/user/userCenter";
    }
}
